// packagePay/pages/insurance-report/insurance-report.js
import {
    insuranceReportList
} from '../../api/insurance'
// import { dateFormat } from '../../../utils/util'
import user from '../../../utils/user'
Page({
    /**
     * 页面的初始数据
     */
    data: {
        tabIndex: 0,
        reportList: [],
        waitFor: [],
        handle: [],
        end: [],
        reject: [],
        revoke: [],
        sure: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {},
    onShow() {
        user.waitLogin().then(() => {
            this.getInsuranceReportList()
        })
    },
    // 拿到页面list
    getInsuranceReportList() {
        insuranceReportList({
            companyId: user.companyId,
            insureCompanyType: 'insure_type_rrb'
        }).then(res => {
            res.forEach((item, index) => {
                if (item.idCardNo) {
                    res[index].idCardNo = item.idCardNo.substring(item.idCardNo.length - 4)
                } else {
                    res[index].idCardNo = '暂无'
                }
                if (item.reportStatus === 6) {
                    item.reportStatus = 2
                }
            })
            this.setData({
                reportList: res
            })
        })
    },
    // 跳转到详情
    onGoReport(event) {
        console.log(event, 'event')
        let {
            id
        } = event.currentTarget.dataset
        wx.navigateTo({
            url: '/packageInsurance/pages/insurance-success/insurance-success?id=' + id,
        })
    },
    onTab(event) {
        let {
            detail
        } = event
        this.setData({
            tabIndex: detail
        })
        this.setData({
            waitFor: this.listFilter(0),
            handle: this.listFilter(1),
            end: this.listFilter(2),
            reject: this.listFilter(3),
            revoke: this.listFilter(4),
            sure: this.listFilter(5),
        })

    },
    onAddInsurance() {
        wx.navigateTo({
            url: '/packageInsurance/pages/insurance-search/insurance-search?outDangerDate=' + '',
        })
    },
    listFilter(type) {
        return this.data.reportList.filter((item) => {
            return item.reportStatus === type
        })
    }
})